package com.tg.app.view;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.appbase.custom.config.ApiUrl;
import com.tg.app.R;
import com.tg.app.helper.DeviceHelper;
import com.tg.app.util.UriUtil;
import com.tg.data.bean.DeviceItem;
import com.tg.data.bean.DeviceSettingsInfo;

public class SimServicePayBanner extends LinearLayout {
    private TextView  simStatusText,payStatusText;
    public SimServicePayBanner(Context context) {
        super(context);
        initView(context);
    }

    public SimServicePayBanner(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }



    public SimServicePayBanner(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }
    private void initView(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_sim_pay_banner,this,true);
        simStatusText = view.findViewById(R.id.sim_banner_status);
        payStatusText = view.findViewById(R.id.sim_pay_status);

    }
    public void updateView(DeviceItem item){
        if (item==null||item.sim_server_data==null){
            setVisibility(GONE);
            return;
        }
        setOnClickListener(v -> {
            DeviceSettingsInfo info = new DeviceSettingsInfo();
            info.deviceID = item.id;
            info.uuid = item.uuid;
             if (DeviceHelper.isCar(item)) {
                UriUtil.openServePlay((Activity) getContext(), ApiUrl.CAR_BUY_PAGE, item == null ? 0 : item.id, 0, Activity.RESULT_FIRST_USER);
            } else if (DeviceHelper.is4GDevice(item)) {
                UriUtil.openServePlay((Activity) getContext(), ApiUrl.SIM_BUY_PAGE, item == null ? 0 : item.id, 0, Activity.RESULT_FIRST_USER);
            }

        });
       if (item.sim_server_data.isFree()){
            simStatusText.setText(R.string.sim_free_used);
            payStatusText.setText(R.string.sim_buy);
            setVisibility(VISIBLE);
        } else if (item.sim_server_data.isExpireing()){
            simStatusText.setText(R.string.sim_service_expiring);
            payStatusText.setText(R.string.sim_service_recharge);
            setVisibility(VISIBLE);
        }
    }

}
